import type { User } from '@/types/user.d'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    // 1. 用户信息
    const user = ref<User>()

    // 2. 修改用户信息
    const setUser = (u: User) => (user.value = u)

    // 3. 删除用户信息
    const delUser = () => (user.value = undefined)

    const returnUrl = ref('')
    const setReturnUrl = (url: string) => (returnUrl.value = url)

    return { user, setUser, delUser, returnUrl, setReturnUrl }
  },
  {
    persist: true
  }
)
